Skip to content

fix(create): Add helpful error messages for hyphen-prefixed function names mis-parsed as flags#3167

Merged
knative-prow[bot] merged 2 commits intoknative:mainfrom
RayyanSeliya:fix-create
Nov 11, 2025
Merged

fix(create): Add helpful error messages for hyphen-prefixed function names mis-parsed as flags#3167
knative-prow[bot] merged 2 commits intoknative:mainfrom
RayyanSeliya:fix-create

Conversation

@RayyanSeliya
Copy link
Copy Markdown
Contributor

Changes

  • 🐛 Fix confusing errors when function names start with hyphens
  • 🎁 Add DNS-1035 naming guidance for mis-parsed arguments
  • ✨ Detect hyphen-prefixed names across multiple error paths

Adds detection and helpful error messages when function names starting with hyphens (e.g., -test-func, --production-func, -123) are mis-parsed as CLI flags. Users now receive clear guidance about DNS-1035 naming rules instead of confusing "template not found" or "unknown flag" errors.

Implementation:

  • Add wrapFlagParsingError() and wrapFlagParsingErrorWithDetails() helper functions (cmd/errors.go)
  • Add custom flag error handler in NewCreateCmd() to intercept Cobra flag parsing errors (cmd/create.go)
  • Enhance newInvalidRuntimeError() and newInvalidTemplateError() to detect mis-parsed names (cmd/create.go)

Error Message Example:

Error: The template 'est-func' was not found for language runtime 'go'.
Available templates for this language runtime are:
  cloudevents
  http

Note: It looks like '-test-func' was interpreted as the flag '-t' with value 'est-func'.
Function names cannot start with hyphens per DNS-1035 naming rules.
Valid function names must start with a letter (a-z) and can contain letters, numbers, and hyphens.

/kind bug

Fixes #3166

Release Note

Function names starting with hyphens now show helpful DNS-1035 naming guidance instead of confusing flag parsing errors

…flags

Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
@knative-prow knative-prow Bot added the kind/bug Bugs label Nov 2, 2025
@knative-prow knative-prow Bot requested review from jrangelramos and nainaz November 2, 2025 18:53
@knative-prow knative-prow Bot added needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files. labels Nov 2, 2025
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Nov 2, 2025

Hi @RayyanSeliya. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 2, 2025

Codecov Report

❌ Patch coverage is 16.66667% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.98%. Comparing base (0bc91f3) to head (ce7c1ed).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
cmd/create.go 26.66% 19 Missing and 3 partials ⚠️
cmd/errors.go 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3167      +/-   ##
==========================================
+ Coverage   59.39%   59.98%   +0.59%     
==========================================
  Files         134      134              
  Lines       13514    13560      +46     
==========================================
+ Hits         8026     8134     +108     
+ Misses       4547     4453      -94     
- Partials      941      973      +32     
Flag Coverage Δ
e2e-tests 41.49% <0.00%> (+1.31%) ⬆️
integration-tests 54.56% <16.66%> (+1.53%) ⬆️
unit-tests 46.61% <16.66%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RayyanSeliya
Copy link
Copy Markdown
Contributor Author

hey @gauron99 can have a look and point me if any tweaks needed !

Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
@RayyanSeliya
Copy link
Copy Markdown
Contributor Author

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels Nov 4, 2025
@RayyanSeliya
Copy link
Copy Markdown
Contributor Author

/cc @gauron99

@knative-prow knative-prow Bot requested a review from gauron99 November 9, 2025 17:01
Copy link
Copy Markdown
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Nov 11, 2025
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented Nov 11, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lkingland, RayyanSeliya

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added the approved 🤖 PR has been approved by an approver from all required OWNERS files. label Nov 11, 2025
@knative-prow knative-prow Bot merged commit fb7f73d into knative:main Nov 11, 2025
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. kind/bug Bugs lgtm 🤖 PR is ready to be merged. ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

func create: Hyphen-prefixed names mis-parsed as flags

2 participants